import { DISK_INIT,CD_DIR_SUCCESS,RETURN_DIR,NEWDIR_SUCCESS,DELETE_SUCCESS,MOVE_SUCCESS ,REFRESH} from '../config/constant'

const disk = (state = {},action) => {
  switch (action.type) {
    case DISK_INIT:{
      state.DirStack.push(action.rootDir)
      return Object.assign({},state,{
        used:action.used,
        quota:action.quota,
        rootDir:action.rootDir,
        Dirs:action.Dirs,
        DirStack:state.DirStack,
        Node:action.Node
      })
    }
    case CD_DIR_SUCCESS:{
      state.DirStack.push(action.DIR)
      return Object.assign({},state,{
        DirStack:state.DirStack,
        Node:action.Node
      })
    }
    case RETURN_DIR:
      return Object.assign({},state,{
        DirStack:action._DirStack
      })
    case NEWDIR_SUCCESS:
      return Object.assign({},state,{
        Dirs:action.Dirs,
        Node:action.Node
      })
    case DELETE_SUCCESS:
      return Object.assign({},state,{
        Dirs:action.Dirs,
        Node:action.Node
      })
    case MOVE_SUCCESS:
      return Object.assign({},state,{
        Dirs:action.Dirs,
        Node:action.Node
      })
    case REFRESH:
      return Object.assign({},state,{
        Node:action.Node
      })
    default:
      return state
  }
}

export default disk
